<%-- 
    Document   : home
    Created on : Feb 15, 2009, 3:04:25 PM
    Author     : leoomoreira
--%>
<%@ taglib prefix="s" uri="/struts-tags" %>

<%@ include file="header.jsp" %>

<h1>SednaAdmin for Web</h1>

<ul id="menu_dropdown" class="menubar">
<li class="submenu"><a href="#">Server</a>
    <ul class="menu">
        <li class="item"><a href="javascript:connectServer();">Connect</a></li>
        <li class="item"><a href="javascript:disconnectServer();">Disconnect</a></li>
        <li class="item"><a href="javascript:showConfigurationServer();">Configuration</a></li>
    </ul>
</li>
<li class="submenu"><a href="#">Database</a>
    <ul class="menu">
        <li class="item"><a href="javascript:startDatabase();">Start</a></li>
        <li class="item"><a href="javascript:stopDatabase();">Stop</a></li>
        <li class="item"><a href="javascript:showConnectDatabase();">Connect</a></li>
        <li class="item"><a href="javascript:disconnectDatabase();">Disconnect</a></li>
        <li class="item"><a href="javascript:createDatabase();">Create</a></li>
        <li class="item"><a href="javascript:dropDatabase();">Drop</a></li>        
    </ul>
</li>
<li class="submenu"><a href="#">Document</a>
    <ul class="menu">
        <li class="item"><a href="javascript:showLoadDocument();">Load</a></li>
    </ul>
</li>
</ul>
<br />
<br />
<div id="connectDatabase" style="display:none; text-align:left;">
    <label><b><center>Connect to database</center></b></label>
    <br />
    <br />
    <label><b>Host</b></label><br />
    <input type="text" id="connectDatabase.host" value="localhost" /><br />
    <label><b>Database</b></label><br />
    <input type="text" id="connectDatabase.database" /><br />
    <label><b>User</b></label><br />
    <input type="text" id="connectDatabase.user" value="SYSTEM" /><br />
    <label><b>Password</b></label><br />
    <input type="text" id="connectDatabase.password" value="MANAGER" /><br />
    <br />
    <div align="center">
    <input type="button" value="Connect" onclick="javascript:connectDatabase();" />&nbsp;
    <input type="button" value="Cancel" onclick="javascript:Lightbox.hideAll();" />
    </div>
</div>
<div id="configuration" style="display:none; text-align:left;">
    <label><b><center>Server configuration</center></b></label>
    <br />
    <br />
    <label><b>Server path</b></label><br />
    <input type="text" id="configuration.serverPath" value="" /><br />
    <br />
    <div align="center">
    <input type="button" value="Save" onclick="javascript:saveConfiguration();" />&nbsp;
    <input type="button" value="Cancel" onclick="javascript:Lightbox.hideAll();" />
    </div>
</div>
<div id="loadDocument" style="display:none; text-align:left;">
<s:form action="server!loadDocument.action" enctype="multipart/form-data" name="loadDocumentForm" id="loadDocumentForm" method="POST" theme="simple">
    <label><b><center>Load document</center></b></label>
    <br />
    <br />
    <label><b>Database</b></label><br />
    <s:textfield name="database" id="loadDocument.database" />
    <br />
    <label><b>File</b></label><br />
    <s:file name="upload" />
    <br />
    <br />
    <iframe id="iframeUpload" name="iframeUpload" src="" style="width: 100px; height: 50px; border: 0px; visibility: hidden;"></iframe>
    <div align="center">
    <input type="submit" value="Load" />&nbsp;
    <input type="button" value="Cancel" onclick="javascript:Lightbox.hideAll();" />
    </div>
</s:form>
</div>

<div style="padding-top: 10px; padding-bottom: 7px;">
    <a href="javascript:connectServer();"><img src="images/icons/serverConnect.png" alt="Connect to server" /></a>
    <a href="javascript:disconnectServer();"><img src="images/icons/serverDisconnect.png" alt="Disconnect from server" /></a>
    &nbsp;
    <a href="javascript:startDatabase();"><img src="images/icons/databaseStart.png" alt="Start database" /></a>
    <a href="javascript:stopDatabase();"><img src="images/icons/databaseStop.png" alt="Stop database" /></a>
    &nbsp;
    <a href="javascript:showConnectDatabase();"><img src="images/icons/databaseConnect.png" alt="Connect to database" /></a>
    <a href="javascript:disconnectDatabase();"><img src="images/icons/databaseDisconnect.png" alt="Disconnect from database" /></a>
</div>
<table width="100%" style="margin: 0px; padding: 0px;" cellspacing="0" cellpadding="0" border="0">
    <tr>
        <td width="350" valign="top">
            <div id="tree" class="tree">
            </div>
        </td>
        <td width="10" valign="top"></td>
        <td valign="top">
            <div id="view" class="box-view" style="width: 800px; height:700px;">
                <div id="a_tabbar" style="width: 800px; height: 700px;"></div>  
            </div>  
        </td>

    </tr>
</table>
<br />
<div class="box-message" id="message" style="overflow: auto; height: 100px;"></div>
<br />

<%@ include file="footer.jsp" %>

<script>
    tabbar = new dhtmlXTabBar("a_tabbar", "top");
    tabbar.setImagePath("tabbar/imgs/"); 
    
    createNewTab();
    createNewTab();
    createNewTab();
    
    clearNavigator();
    Lightbox.hideAll();
    new Lightbox.base('waitingBox');
    var json = getJsonGet('server!statusServer.action');
    Lightbox.hideAll();
    if (json != '' && json.reason != '') {
        if (json.reason == 'true') {
            for (var k = 0; json.messages != '' && k < json.messages.length; k++)
                $('message').innerHTML = '<h2 class="success">' + json.messages[k].message + '<br /></h2>' + $('message').innerHTML;
            getDatabases();
        }
        else {
            for (var k = 0; json.errorMessages != '' && k < json.errorMessages.length; k++)
                $('message').innerHTML = '<h2 class="failure">' + json.errorMessages[k].errorMessage + '<br /></h2>' + $('message').innerHTML;
        }
    }
    else {
        alert('Error');
    }
    
    tabbar.setTabActive("tab1");
    
    function initUpload() {
        document.getElementById('loadDocumentForm').onsubmit=function() {
            document.getElementById('loadDocumentForm').target = 'iframeUpload';
            document.getElementById("iframeUpload").onload = uploadDone;
        }
    }
    
    function uploadDone() {
        var ret = frames['iframeUpload'].document.getElementsByTagName("body")[0].innerHTML;
        var json = eval("("+ret.substring(5, ret.length - 6)+")");
        if (json.reason == 'true') {
            var message = '';
            for (var i = 0; i < json.messages.length; i++) {
                message += json.messages[i].message + '\n';
            }
            alert(message);
            updateDocuments($('loadDocument.database').value);
            Lightbox.hideAll();
        }
        else {
            var message = '';
            for (var i = 0; i < json.errorMessages.length; i++) {
                message += json.errorMessages[i].errorMessage + '\n';
            }
            alert(message);
        }
	
    }
    
    initUpload();

</script>